#pragma once

// C std
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

// linux
#include <unistd.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/signal.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <net/if.h>
#include <setjmp.h>

struct rtt_info {
    
    float   rtt_rtt;    /* most recent measured, in second 当前测得的RTT数值 */
    float   rtt_srtt;   /* smoothed RTT estimator, in second 当前平滑化RTT估算因子 */
    float   rtt_rttvar; /* 平滑化平均偏差估算因子*/
    float   rtt_rto;
    int     rtt_nrexm;  /* retry number (or times retransmitted: 0,1,2,3)*/

    uint32_t    rtt_base;   /* sec since 1/1/1970 at start */
};

#define RTT_RXMIN   2
#define RTT_RXMAX   60
#define RTT_MAXNREXMT   3   /* max # times to retransmit */


void rtt_debug(struct rtt_info *);
void rtt_init(struct rtt_info *);
void rtt_newpack(struct rtt_info *);
int rtt_start(struct rtt_info *);
void rtt_stop(struct rtt_info *, uint32_t);
int rtt_timeout(struct rtt_info *);
uint32_t rtt_ts(struct rtt_info * );

extern int rtt_d_flag;  // can be set to nonzero for addl info


